<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            ref="searchInput"
            placeholder="请输入内容"
            clearable
            @clear="getGoodsList"
            v-model="queryData.query"
            @click="getGoodsList"
          >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <!-- 商品表格 -->
        <el-table :data="goodsList" style="width: 100%" border stripe>
          <el-table-column label="#" type="index"></el-table-column>
          <el-table-column
            prop="order_number"
            label="订单编号"
            width="360"
          ></el-table-column>
          <el-table-column
            prop="order_price"
            label="订单价格"
            width="150"
          ></el-table-column>
          <el-table-column prop="pay_status" label="是否付款" width="150">
            <template slot-scope="scope">
              <el-tag type="danger" v-if="scope.row.pay_status == '0'"
                >未付款
              </el-tag>
              <el-tag v-else type="success">已付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            prop="is_send"
            label="是否发货"
            width="150"
          ></el-table-column>
          <el-table-column prop="create_time" label="下单时间" width="260">
            <template slot-scope="scope">
              {{ scope.row.create_time | dateFormat }}
            </template>
          </el-table-column>
          <!-- 操作列 -->
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button :order=scope.id
                type="primary"
                icon="el-icon-edit"
                size="mini"
                @click="isEditAddressShow = true"
              ></el-button>
              <el-button
                type="success"
                icon="el-icon-s-tools"
                size="mini"
                @click="showProgressDialog"
              ></el-button
            ></template>
          </el-table-column>
        </el-table>
        <!-- 页码条 -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="pageChange"
          :current-page="queryData.pagenum"
          :page-sizes="[5, 10, 20, 50]"
          :page-size="queryData.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-row>
    </el-card>
    <!-- 编辑对话框 -->
    <el-dialog title="修改地址" :visible.sync="isEditAddressShow" width="30%">
      <!-- 级联选择器 -->
      <el-cascader
        v-model="selectedIds"
        :options="cityList"
        :props="{ expandTrigger: 'hover' }"
      ></el-cascader>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isEditAddressShow = false">取 消</el-button>
        <el-button type="primary" @click="isEditAddressShow = false"
          >确定修改</el-button
        >
      </span>
    </el-dialog>
    <!-- 物流对话框 -->
    <el-dialog
      title="物流进度"
      :visible.sync="isProgressDialogShow"
      width="50%"
    >
      <!-- 时间线组建 物流进度-->
      <el-timeline reverse="reverse">
        <el-timeline-item
          v-for="(item, index) in info"
          :key="index"
          :timestamp="item.time"
        >
          {{ item.time }}
          {{ item.context }}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isProgressDialogShow = false">取 消</el-button>
        <el-button type="primary" @click="isProgressDialogShow = false"
          >确定修改</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
// 引入城市列表js 文件
import cityList from './citydata.js'
export default {
  created () {
    this.getGoodsList()
  },
  data () {
    return {
      // 商品列表查询条件
      queryData: {
        query: '',
        pagenum: 1,
        pagesize: 5,
        user_id: '',
        pay_status: '',
        is_send: '',
        order_number: '',
        // eslint-disable-next-line no-dupe-keys
        pay_status: ''
      },
      // 商品列表总数
      goodsList: [],
      //   总商品数量
      total: 0,
      // 修改地址对话框
      isEditAddressShow: false,
      // 城市列表
      cityList,
      // 级联选择器绑定数据
      selectedIds: [],
      // 物流信息对话框
      isProgressDialogShow: false,
      // 物流信息列表
      info: []
    }
  },
  methods: {
    // 商品列表
    async getGoodsList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryData
      })
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.goodsList = res.data.goods
      this.total = res.data.total
    },
    //
    handleSizeChange (newSize) {
      this.queryData.pagesize = newSize
      //   重新渲染表格数据
      this.getGoodsList()
    },
    //
    pageChange (newPage) {
      this.queryData.pagenum = newPage
      this.getGoodsList()
    },
    // 删除事件
    doDel (rowData) {
      this.$messageBox.confirm('确定要删除吗？', '系统提示', {
        confirmButtonText: '确定',
        callback: async (action) => {
          if (action === 'cancel') return
          // 请求接口
          const { data: res } = await this.$http.delete(
            `goods/${rowData.goods_id}`
          )
          if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
          this.$message.success(res.meta.msg)
          this.getGoodsList()
        }
      })
    },
    // 跳转到 添加商品页面
    addJump () {
      this.$router.push('/goods/add')
    },
    // 显示物流信息
    async showProgressDialog () {
      this.isProgressDialogShow = true
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      this.info = res.data
    }
  }
}
</script>

<style lang="less" scoped>
</style>
